<%@page import="java.util.ArrayList"%>
<%@page import="java.util.LinkedHashMap"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.general.Util"%>
<%@page import="com.alibaba.fastjson.JSON"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
Map<String,List<JSONObject>> map = new LinkedHashMap<String, List<JSONObject>>();
String workFlowId = Util.null2String(request.getParameter("workFlowId"));
if("".equals(workFlowId)) workFlowId = "-1";
String mainTableName = "main";
RecordSet rs = new RecordSet();
rs.executeSql("select tablename from workflow_bill where id in(select formid from workflow_base where id= '"+workFlowId+"' )");
if(rs.next()){
	mainTableName = Util.null2String(rs.getString("tablename"));
}
rs.executeSql("SELECT B.ID,B.FIELDNAME,B.FIELDDBTYPE,E.LABELNAME,B.DETAILTABLE,C.ORDERID FROM WORKFLOW_BASE A LEFT JOIN WORKFLOW_BILLFIELD B ON B.BILLID = A.FORMID LEFT JOIN WORKFLOW_BILLDETAILTABLE C ON C.TABLENAME = B.DETAILTABLE LEFT JOIN HTMLLABELINFO E ON E.INDEXID = B.FIELDLABEL AND E.LANGUAGEID = 7 WHERE A.ID = '"+workFlowId+"' ORDER BY B.DETAILTABLE,B.ID");
while(rs.next()){
	String orderId = Util.null2String(rs.getString("ORDERID"));
	if("".equals(orderId)) orderId = "0";
	String fieldName = Util.null2String(rs.getString("FIELDNAME"));
	String fieldId = "field"+Util.null2String(rs.getString("ID"));
	String fieldDbType = Util.null2String(rs.getString("FIELDDBTYPE"));
	String labelName = Util.null2String(rs.getString("LABELNAME"));
	String detailTable = Util.null2String(rs.getString("DETAILTABLE"));
	if( "".equals(detailTable) ) detailTable = mainTableName;
	if(!map.containsKey(detailTable)){
		map.put(detailTable,new ArrayList<JSONObject>());
	}
	List<JSONObject> list = map.get(detailTable);
	JSONObject json = new JSONObject();
	json.put("fieldId",fieldId);
	json.put("fieldName",fieldName);
	json.put("fieldType",fieldDbType);
	json.put("labelName",labelName);
	list.add(json);
}
out.print(JSON.toJSONString(map));
%>
